package com.hellobike.haxing.modules.wms.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hellobike.haxing.modules.wms.entity.Warehouse;
import com.hellobike.haxing.modules.wms.entity.WarehouseDepart;
import com.hellobike.haxing.modules.wms.mapper.WarehouseDepartMapper;
import com.hellobike.haxing.modules.wms.service.IWarehouseDepartService;
import com.hellobike.haxing.modules.wms.service.IWarehouseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

/**
 * @Description: t_wms_warehouse_depart
 * @Author: haxing-boot
 * @Date: 2020-01-10
 * @Version: V1.0
 */
@Service
public class WarehouseDepartServiceImpl extends ServiceImpl<WarehouseDepartMapper, WarehouseDepart> implements IWarehouseDepartService {

    @Autowired
    private IWarehouseService warehouseService;
    @Override
    public Long getWarehouseIdByDepartCode(String orgCode) {
        WarehouseDepart q = new WarehouseDepart();
        q.setDepartCode(orgCode);
        WarehouseDepart warehouseDepart = baseMapper.selectOne(new QueryWrapper<>(q));
        if (warehouseDepart != null) {
            return warehouseDepart.getWarehouseId();
        }
        return -1L;
    }

    @Override
    public Warehouse getWarehouseByDepartCode(String orgCode) {
        WarehouseDepart q = new WarehouseDepart();
        q.setDepartCode(orgCode);
        WarehouseDepart warehouseDepart = baseMapper.selectOne(new QueryWrapper<>(q));
        if (warehouseDepart != null) {
            return warehouseService.getById(warehouseDepart.getWarehouseId());
        }
        return null;
    }
}
